﻿
function CustomDbClick() {
    parent.closeWin(); //去掉双击功能
}


//新增
var fnCustomAdd = function () {
    const_EditEntity = "salSalarySolution";
    var pagetitle = "新增薪资方案";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity));
    parent.NeedRefreshPage = this;
}
//修改
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "salSalarySolution";
    var pagetitle = "修改薪资方案—" + record.getData("Name");
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID)));
    parent.NeedRefreshPage = this;
}
//调整薪资项
var fnEditSalaryItem = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var id = record.getData(const_entityID);
    var name = record.getData("Name")
    var pagetitle = "调整薪资项—" + name;
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/YUIDataTableList.aspx?r=" + Math.random() + "&entity=V_salSalaryItemSolution&Condition=SalarySolutionID='" + id + "'&name=" + name + "&id=" + id + "&functionId=E52B3F68-68D6-403D-A8AF-2F59D61FC3FC"));
    parent.NeedRefreshPage = this;
}

var salarySolutionID = "";
var flag = "0";//0－部门，1－岗位，2－个人；
//适用部门
var fnSelectDept = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    salarySolutionID = record.getData(const_entityID);
    flag = "0";
    document.getElementById("dialog1_h").innerHTML = "适用部门";
    document.getElementById("EditUIWindow").src = "../EditWidows/YUITree.aspx?r=" + Math.random() + "&entity=DatDepartment&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|True";
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
    //setTimeout(getCheckedNodes, 200);
    getCheckedNodes();
}

//适用岗位
var fnSelectPost = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    salarySolutionID = record.getData(const_entityID);
    flag = "1";
    document.getElementById("dialog1_h").innerHTML = "适用岗位";
    document.getElementById("EditUIWindow").src = "../EditWidows/YUITree.aspx?r=" + Math.random() + "&entity=DatPost&masterPara=DatPost|PostName|PostID|ParentID|DeptID|True&IsHighlightUpDown=false&IsExpandAll=false";
    SetDWH(550, 480, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
    setTimeout(getCheckedNodes, 200);
    //getCheckedNodes();
}

//选择个人
var fnSelectEmp = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    salarySolutionID = record.getData(const_entityID);
    flag = "2";
    document.getElementById("dialog1_h").innerHTML = "适用个人";
    document.getElementById("EditUIWindow").src = "../EHR/hrSelectEmp.aspx?solutionId=" + salarySolutionID + "&type=1&r=" + Math.random();
    SetDWH(600, 450, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//调用YUITree.aspx的ChooseInfo方法，获取选中部门、岗位
var getChooseInfo = function () {
    var editwindow = document.getElementById("EditUIWindow");
    if (editwindow) {
        editwindow.contentWindow.ChooseInfo();
    }
}

//返回选中部门或岗位
var _fn = function (ids, names) {
    //if (ids == undefined || ids == "undefined") ids = "";
    if (ids == "" || ids == undefined) return;
    //alert("ids:" + ids + "  names:" + names);
    //保存到数据库
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrSalaryAjax.aspx?flag=saveSalaryDeptSolution&ids=" + ids + "&type=" + flag + "&SolutionID=" + salarySolutionID, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    alert("保存成功！");
                }
                else {
                    if (str.substr(0, 1) == "e") {
                        alert(str.substr(1, str.length - 1));
                    }
                    else {
                        alert("保存失败！");
                    }
                }
            }
            catch (e) { }
            finally { }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);

    YAHOO.example.container.dialog1.hide();
}

//得到已经选择的部门或岗位
var getCheckedNodes = function () {
    var editwindow = document.getElementById("EditUIWindow");
    var request = "../Extend/AjaxData/DataProcessin.aspx?action=Get&entity=salDeptSolution&condition=SolutionID='" + salarySolutionID + "' and Flag=" + flag;
    YAHOO.util.Connect.asyncRequest('POST', request, {
        success: function (res) {
            var inventory;
            try {
                var str = res.responseText;
                var ids = [];
                var items = eval("[" + str + "]");
                for (var i = 0; i < items[0].rows.length; i++) {
                    ids.push(items[0].rows[i].DeptID);
                }
                ids = ids.join(",");
                if (editwindow) {
                    editwindow.contentWindow.checkSelectedNode(ids);
                }
            }
            catch (e) {
            }
            finally {
            }
        },
        failure: function (error) {
            alert("读取节点数据错误：" + error.statusText);
        }
    }, null);
}

//单元格格式化
var fnFormater = function (elCell, oRecord, oColumn, sData) {
    var cellValue = sData;
    if (cellValue != null && cellValue.length > 200) {
        cellValue = cellValue.substr(0, 200) + "...";
    }
    elCell.innerHTML = "<div title='" + sData + "'>" + cellValue + "</div>";
}

//初始化
$(document).ready(function () {
    var btn = $("#yui-gen7-button");
    btn.click(function () {
        getChooseInfo();
    });
});

////删除第一步
//var fnCustomDelete = function () {
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    if (record == null) {
//        alert("请选择一条记录");
//        return;
//    }
//    var id = record.getData(const_entityID);
//    //第一步先删除该薪资方案对应的薪资项目
//    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrSalaryAjax.aspx?flag=deleteSalarySolution&id=" + id, {
//        success: function (res) {
//            try {
//                var str = res.responseText;
//                if (str == "0") {
//                    //第二步
//                    var list = mDataTable.getRecordSet()._records;
//                    dl = [];
//                    for (var i = 0; i < list.length; i++) {
//                        if (list[i]._oData["iSun_Selected"] == true) {
//                            dl.push(list[i]._sId); //获取行ID；
//                        }
//                    }
//                    SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + id;
//                    YAHOO.example.container.dialog3.show();
//                }
//                else {
//                    alert("薪资方案对应的薪资项删除失败，请手动删除！");
//                    return;
//                }
//            }
//            catch (e) {
//                alert("删除失败：" + e.Message);
//                return;
//            }
//            finally {
//            }
//        },
//        failure: function (error) {
//            alert("数据错误：" + error.statusText);
//            return;
//        }
//    }, null);
//}